<?php
namespace app\mobile\controller;
use think\Db;
use clt\Leftnav;
use think\Controller;
class Common extends Controller
{
    public function initialize()
    {
        if(!isMobile()){
            $this->redirect('home/index/index');
        }
        $sys = cache('System');
        $this->assign('sys',$sys);

        //导航
//        $cate = cache('cate');
//        if(!$cate){
//            $column_one = Db::name('category')->where([['pid','=',0],['ismenu','=',1]])->order('sort')->select();
//            $column_two = Db::name('category')->where('ismenu',1)->order('sort')->select();
//            $tree = new Leftnav ();
//            $cate = $tree->index_top($column_one,$column_two);
//            cache('cate', $cate, 3600);
//        }
        $cate = Db::name('category')->where([['pid','=',0],['ismenu','=',1]])->order('sort')->select();
        $this->assign('category',$cate);

        //二级导航
        $thisCat = Db::name('category')->where('id',input('catId'))->find();
        $this->assign('title',$thisCat['title']);
        $this->assign('catname',$thisCat['catname']);
        $this->assign('keywords',$thisCat['keywords']);
        $this->assign('description',$thisCat['description']);
        $this->assign('catid',$thisCat['id']);//当前栏目ID
        $this->assign('pid',$thisCat['pid']);//当前栏目PID
        define('DBNAME',strtolower($thisCat['module']));
        $this->pagesize = $thisCat['pagesize']>0 ? $thisCat['pagesize'] : '';

        //广告
        $adMoblicList = cache('adMoblicList');
        if(!$adMoblicList){
            $adMoblicList = Db::name('ad')->where(['as_id'=>2,'open'=>1])->order('sort asc')->limit('5')->select();
            cache('adMoblicList', $adMoblicList, 3600);
        }
        $this->assign('adList', $adMoblicList);

        //关于我们和练习我们
        $aboutData = cache('aboutData');
        if(!$aboutData){
            $aboutData = Db::name('page')->where(['status'=>1])->limit('2')->select();
            cache('aboutData', $aboutData, 3600);
        }
        $aboutInfo =$aboutData[0];
        $lxInfo = $aboutData[1];

        $this->assign('aboutInfo', $aboutInfo);
        $this->assign('lxInfo', $lxInfo);

        //畅言
        //$plugin = db('plugin')->where(['code'=>'changyan'])->find();
       // $this->changyan = unserialize($plugin['config_value']);
        //$this->assign('changyan', $this->changyan);
    }
    //空操作
    public function _empty(){
        return $this->error('空操作，返回上次访问页面中...');
    }
}
